#!/usr/bin/env bash

# This script uses MESOS_SOURCE_DIR and MESOS_BUILD_DIR which come
# from configuration substitutions.
MESOS_SOURCE_DIR=@abs_top_srcdir@
MESOS_BUILD_DIR=@abs_top_builddir@

# Use colors for errors.
. ${MESOS_SOURCE_DIR}/support/colors.sh

# Force the use of the Python interpreter configured during building.
test ! -z "${PYTHON}" && \
  echo "${RED}Ignoring PYTHON environment variable (using @PYTHON@)${NORMAL}"

PYTHON=@PYTHON@

DISTRIBUTE=`echo ${MESOS_BUILD_DIR}/3rdparty/distribute-*/`

# Just warn in the case when build with --disable-bundled.
test ! -e ${DISTRIBUTE} && \
  echo "${RED}Failed to find ${DISTRIBUTE}${NORMAL}"

PROTOBUF=`echo ${MESOS_BUILD_DIR}/3rdparty/libprocess/3rdparty/protobuf-*/python/`

test ! -e ${PROTOBUF} && \
  echo "${RED}Failed to find ${PROTOBUF}${NORMAL}"

MESOS_EGGS=$(find ${MESOS_BUILD_DIR}/src/python/dist -name "*.egg" | tr "\\n" ":")

SCRIPT=${MESOS_SOURCE_DIR}/src/examples/python/test_containerizer.py

test ! -e ${SCRIPT} && \
  echo "${RED}Failed to find ${SCRIPT}${NORMAL}" && \
  exit 1

PYTHONPATH="${DISTRIBUTE}:${PROTOBUF}:${MESOS_EGGS}" \
  exec ${PYTHON} ${SCRIPT} "${@}"
